﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.WarehouseInsp.Buz.JHWorkflow;
using Microhard.WarehouseInsp.Buz.Models;
using Microhard.WarehouseInsp.Buz.DTO;

namespace Microhard.WarehouseInsp.Buz.Impls
{
    public class CustomerImpl : ICustomer
    {
        public Core.DBUtility.ExecutedResult Add(Models.CustomerModel model)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Update(Models.CustomerModel model)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Delete(List<Guid> ids)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Delete(Models.CustomerModel model)
        {
            throw new NotImplementedException();
        }

        public Models.CustomerModel GetModelByID(Guid id)
        {
            throw new NotImplementedException();
        }

        public Models.CustomerModel GetModelByModel(Models.CustomerModel model)
        {
            throw new NotImplementedException();
        }

        public List<Models.CustomerModel> Query(Models.CustomerModel Model, int pageIndex, int pageSize, out int totalCount)
        {
            C6Entities db = new C6Entities();
            IEnumerable<JHBJ_Crm_Customer> entities = from b in db.JHBJ_Crm_Customer
                                                      select b;
            if (!string.IsNullOrEmpty(Model.Customer_Name))
            {
                entities = from b in db.JHBJ_Crm_Customer
                           where b.Customer_Name.IndexOf(Model.Customer_Name) > -1
                           select b;
            }
            totalCount = entities.Count();
            var pagedEntities = entities.OrderByDescending(p => p.Customer_Name).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            if (pagedEntities != null && pagedEntities.Count > 0)
                return pagedEntities.Select(m => m.ToModel()).ToList();
            return new List<CustomerModel>();
        }

        public List<Models.CustomerModel> Query(Models.CustomerModel Model)
        {
            C6Entities db = new C6Entities();
            IEnumerable<JHBJ_Crm_Customer> entities = from b in db.JHBJ_Crm_Customer
                                                      select b;
            if (!string.IsNullOrEmpty(Model.Customer_Name))
            {
                entities = from b in db.JHBJ_Crm_Customer
                           where b.Customer_Name.IndexOf(Model.Customer_Name) > -1
                           select b;
            }
            if (entities.Count() > 0)
                return entities.Select(m => m.ToModel()).ToList();
            return new List<CustomerModel>();
        }

        public Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
